package com.demo.flightInfo;

import com.demo.common.constant.ConstantDtoFlight;
import com.demo.common.dto.DtoFlightResult;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class FlightNoValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		validateRegex("fno", "[a-zA-Z0-9]{2}[0-9]{3,4}", "fnoMsg", "航班号输入有误");
	}

	@Override
	protected void handleError(Controller c) {
		DtoFlightResult dtoFlightResult = new DtoFlightResult();
		dtoFlightResult.setFno(c.getPara("fno"));
		dtoFlightResult.setMessage(ConstantDtoFlight.message_fno_invalid);
		dtoFlightResult.setCode(ConstantDtoFlight.code_fno_invalid);
		c.renderJson(dtoFlightResult);
	}

}
